//
//  NetworkManager.swift
//  LunchDecider
//
//  Created by 王阳 on 2017/5/16.
//  Copyright © 2017年 WayneStudio. All rights reserved.
//  https://github.com/Alamofire/Alamofire
//  http://httpbin.org

import Foundation
import Alamofire

enum requestType {
    case get
    case post
}

class NetworkManager {
    static let sharedInstance = NetworkManager.init()
    private init() {
        
    }
    
    final class func finalFunc() {
        
    }
    
    static func requestData(_ type: requestType, URLString: String, parameters: [String: Any]? = nil, finishCallBack: @escaping (_ result: Any) -> ()) {
        
        let method = (type == .get ? HTTPMethod.get : HTTPMethod.post)
        
        Alamofire.request(URLString, method: method, parameters: parameters)
            .responseString(completionHandler: { (response) in
                print("===\n request:\(String(describing: response.request!))")
                print("response:\(String(describing: response.response!))")
                print("===\n value:\(String(describing: response.value!))")
                print("===\n success:\(response.result.isSuccess)")
            })
            .responseJSON { (response) in
            guard let result = response.result.value else {
                print(response.result.error!)
                return
            }
            finishCallBack(result)
        }
    }
}
